package com.gzl.demo.controller;

import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyun.teaopenapi.models.Config;

/**
 * <p>
 *
 * </p>
 *
 * @author gzl
 * @since 2021/7/7
 */
public class SmsDemo {
    /**
     * 使用AK&SK初始化账号Client
     * @param accessKeyId
     * @param accessKeySecret
     * @return Client
     * @throws Exception
     */
    public static com.aliyun.dysmsapi20170525.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        Config config = new Config()
                // 您的AccessKey ID
                .setAccessKeyId(accessKeyId)
                // 您的AccessKey Secret
                .setAccessKeySecret(accessKeySecret);
        // 访问的域名
        config.endpoint = "dysmsapi.aliyuncs.com";
        return new com.aliyun.dysmsapi20170525.Client(config);
    }

    public static void main(String[] args_) throws Exception {
        String param ="250250";
        com.aliyun.dysmsapi20170525.Client client = SmsDemo.createClient("LTAI5tLTQorrWMvjCJgmGfy9", "Iev8EDSyvlorPFlk9kfwtjJqJHQSQm");
        SendSmsRequest sendSmsRequest = new SendSmsRequest();
        sendSmsRequest.setPhoneNumbers("18435223930");
        sendSmsRequest.setSignName("传智健康");
        sendSmsRequest.setTemplateCode("SMS_176480184");
        sendSmsRequest.setTemplateParam("{\"code\":\""+param+"\"}");

        // 复制代码运行请自行打印 API 的返回值
        SendSmsResponse sendSmsResponse = client.sendSms(sendSmsRequest);
        System.out.println(sendSmsResponse.getBody().message);
    }
}
